<?php 


require "../common/Curl.php";

/**
 *	https://open.esign.cn/doc/detail?id=opendoc%2Fidentity_service%2Feaug1b&namespace=opendoc%2Fidentity_service
 * 	e签宝 认证服务API
 * 	认证服务纯API版----接口顺序排列封装
 *  使用请求签名鉴权方式
 *  下一个------------------ 企业认证网页版 authorgan.php
 */


//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [createAuthFace 发起个人刷脸实名认证]
 * @param  [type] $accountId    [个人账号id]
 * @param  [type] $faceauthMode [个人刷脸实名认证方式TENCENT  腾讯云认证ZHIMACREDIT  支付宝芝麻信用认证ESIGN  e签宝刷脸]
 * @param  [type] $repetition   [是否允许账号重复实名（默认允许重复实名)]
 * @param  [type] $callbackUrl  [认证完成后业务重定向地址]
 * @param  [type] $contextId    [对接方业务上下文id，将在异步通知及跳转时携带返回对接方]
 * @param  [type] $notifyUrl    [认证结束后异步通知地址]
 * @return [type]               [description]
 */
function createAuthFace($accountId,$faceauthMode,$repetition,$callbackUrl,$contextId,$notifyUrl,$appId,$secret,$url){
	$urlss = $url."/v2/identity/auth/api/individual/".$accountId."/face";
	$head_url = "/v2/identity/auth/api/individual/".$accountId."/face";
    $data = [
		"faceauthMode"=>$faceauthMode,
		"repetition"=>$repetition,
	    "callbackUrl"=>$callbackUrl,
	    "contextId"=>$contextId,
	    "notifyUrl"=>$notifyUrl
	];
    $res = json_encode($data);
    $header = getHeader($data,"POST",$head_url,$appId,$secret,$url);
    $result = sendHttp($method="POST",$urlss,$header,$res);
    return $result;
}     
// $accountId = "9e053884172641a5a464d80fb9dae6c7";
// $faceauthMode = "ZHIMACREDIT";
// $repetition = true;
// $callbackUrl = "http://www.baidu.com";
// $contextId = "201908221430111";
// $notifyUrl = "http://www.baidu.com";
// $a = createAuthFace($accountId,$faceauthMode,$repetition,$callbackUrl,$contextId,$notifyUrl,$appId,$secret,$url);
// var_dump($a);die;

// {"code":0,"message":"成功","data":{"flowId":"1941655139715122056","authUrl":"https://smlt.esign.cn/nyOZa5fpCrj5","originalUrl":"https://openapi.alipay.com/gateway.do?alipay_sdk=alipay-sdk-java-3.7.105.ALL&app_id=2021001155661340&biz_content=%7B%22certify_id%22%3A%22fcc2e5664c983ba27fbae99c4e4ffd16%22%7D&charset=UTF-8&format=JSON&method=alipay.user.certify.open.certify&sign=hbO%2B%2BjDaqRCDsOKwpJPBhJCtVu2IFij4Tg5%2F6pwRDpWZGFMdu2mDc0jeM%2F8kTTxoxn%2B9kmpaeZExs8atskKxByYw5mN13Olv0FdCCOy1lKmVoyQ901C6rnHgaFSypu5K1pWksYe6oKJ%2F%2BCwceL4s94m7s1BGIoRthCGNdYUl0fRcSNpFWkl44CX8IPSUL6E2VmtsRZDx2VV%2BV6rfFdWqf3mq3ldyq1ShwjfJ3JwK121qeW5dl20TYY8S1SQPJNhD47ltgvsTzY7%2FZ%2FOx9hHOFeNG6Pnn0UE9oSlGkO9IfLIhGjRyBENyO1ze25rbNBV5nQtLtssHsJ5iAbIdtNIiXg%3D%3D&sign_type=RSA2×tamp=2021-09-01+11%3A41%3A05&version=1.0","faceToken":null,"expire":1630467785410}}

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [createAuthBody 发起个人刷脸核身认证]
 * @param  [type] $name         [姓名]
 * @param  [type] $idNo         [身份证号]
 * @param  [type] $faceauthMode [个人刷脸实名认证方式]
 * @param  [type] $callbackUrl  [刷脸完成后业务重定向地址]
 * @param  [type] $contextId    [对接方业务上下文id]
 * @param  [type] $notifyUrl    [认证结束后异步通知地址]
 * @return [type]               [description]
 */
function createAuthBody($name,$idNo,$faceauthMode,$callbackUrl,$contextId,$notifyUrl,$appId,$secret,$url){
	$urlss = $url."/v2/identity/auth/api/individual/face";
	$head_url = "/v2/identity/auth/api/individual/face";
    $data = [
    	"name"=>$name,
		"idNo"=>$idNo,
		"faceauthMode"=>$faceauthMode,
	    "callbackUrl"=>$callbackUrl,
	    "contextId"=>$contextId,
	    "notifyUrl"=>$notifyUrl
	];
    $res = json_encode($data);
    $header = getHeader($data,"POST",$head_url,$appId,$secret,$url);
    $result = sendHttp($method="POST",$urlss,$header,$res);
    return $result;
} 
// $name = "刘颂晶";
// $idNo = "360731199907050379";
// $faceauthMode = "TENCENT";
// $callbackUrl = "http://www.baidu.com";
// $contextId = "201908221430111";
// $notifyUrl = "http://www.baidu.com";
// $a = createAuthBody($name,$idNo,$faceauthMode,$callbackUrl,$contextId,$notifyUrl,$appId,$secret,$url);
// var_dump($a);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [createPhoneAuthPerson 发起运营商3要素实名认证]
 * @param  [type] $accountId  [个人账号id]
 * @param  [type] $mobileNo   [手机号]
 * @param  [type] $repetition [是否允许账号重复实名]
 * @param  [type] $contextId  [对接方业务上下文id]
 * @param  [type] $notifyUrl  [认证结束后，异步通知地址]
 * @param  [type] $grade      [指定是否使用运营商3要素信息比对详情版]
 * @return [type]             [description]
 */
function createPhoneAuthPerson($accountId,$mobileNo,$repetition,$contextId,$notifyUrl,$grade,$appId,$secret,$url){
	$urlss = $url."/v2/identity/auth/api/individual/".$accountId."/telecom3Factors";
	$head_url = "/v2/identity/auth/api/individual/".$accountId."/telecom3Factors";
    $data = [
    	"accountId"=>$accountId,
		"mobileNo"=>$mobileNo,
		"repetition"=>$repetition,
	    "contextId"=>$contextId,
	    "notifyUrl"=>$notifyUrl,
	    "grade"=>$grade
	];
    $res = json_encode($data);
    $header = getHeader($data,"POST",$head_url,$appId,$secret,$url);
    $result = sendHttp($method="POST",$urlss,$header,$res);
    return $result;
} 
// $accountId = "9e053884172641a5a464d80fb9dae6c7";
// $mobileNo = "15179798856";
// $repetition = false;
// $contextId = "201908221430111";
// $notifyUrl = "http://www.baidu.com";
// $grade = "STANDARD";
// $a = createPhoneAuthPerson($accountId,$mobileNo,$repetition,$contextId,$notifyUrl,$grade,$appId,$secret,$url);
// var_dump($a);die;  //1941804971779949632

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [createPhoneAuthBody 发起运营商3要素核身认证]
 * @param  [type] $name      [姓名]
 * @param  [type] $idNo      [身份证号]
 * @param  [type] $mobileNo  [手机号]
 * @param  [type] $contextId [对接方业务上下文id]
 * @param  [type] $notifyUrl [实名结束后异步通知地址]
 * @param  [type] $grade     [指定是否使用运营商3要素信息比对详情版]
 * @return [type]            [description]
 */
function createPhoneAuthBody($name,$idNo,$mobileNo,$contextId,$notifyUrl,$grade,$appId,$secret,$url){
	$urlss = $url."/v2/identity/auth/api/individual/telecom3Factors";
	$head_url = "/v2/identity/auth/api/individual/telecom3Factors";
    $data = [
    	"name"=>$name,
		"idNo"=>$idNo,
		"mobileNo"=>$mobileNo,
	    "contextId"=>$contextId,
	    "notifyUrl"=>$notifyUrl,
	    "grade"=>$grade
	];
    $res = json_encode($data);
    $header = getHeader($data,"POST",$head_url,$appId,$secret,$url);
    $result = sendHttp($method="POST",$urlss,$header,$res);
    return $result;
} 
// $name = "刘颂晶";
// $idNo = "360731199907050379";
// $mobileNo = "15179798856";
// $contextId = "201908221430111";
// $notifyUrl = "http://www.baidu.com";
// $notifyUrl = "STANDARD";
// $a = createPhoneAuthBody($name,$idNo,$mobileNo,$contextId,$notifyUrl,$grade,$appId,$secret,$url);
// var_dump($a);die;  //1941810112369263681

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [shotMessageAuth 运营商短信验证码验证]
 * @param  [type] $flowId   [流程id]
 * @param  [type] $authcode [验证码]
 * @return [type]           [description]
 */
function shotMessageAuth($flowId,$authcode,$appId,$secret,$url){
	$urlss = $url."/v2/identity/auth/pub/individual/".$flowId."/telecom3Factors";
	$head_url = "/v2/identity/auth/pub/individual/".$flowId."/telecom3Factors";
	$data = [
		'authcode'=>$authcode
	];
	$res = json_encode($data);
    $header = getHeader($data,"PUT",$head_url,$appId,$secret,$url);
    $result = sendHttp($method="PUT",$urlss,$header,$res);
    return $result;
}
// $flowId = "1941810112369263681";
// $authcode = "253076";
// $a = shotMessageAuth($flowId,$authcode,$appId,$secret,$url);
// var_dump($a);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [createPhoneBankAuthPerson 发起银行4要素实名认证]
 * @param  [type] $accountId  [个人账号id]
 * @param  [type] $mobileNo   [手机号]
 * @param  [type] $bankCardNo [银行卡号]
 * @param  [type] $repetition [是否允许账号重复实名]
 * @param  [type] $contextId  [对接方业务上下文id]
 * @param  [type] $notifyUrl  [认证结束后，异步通知地址]
 * @param  [type] $grade      [指定是否使用银行卡4要素信息比对详情版]
 * @return [type]             [description]
 */
function createPhoneBankAuthPerson($accountId,$mobileNo,$bankCardNo,$repetition,$contextId,$notifyUrl,$grade,$appId,$secret,$url){
	$urlss = $url."/v2/identity/auth/api/individual/".$accountId."/bankCard4Factors";
	$head_url = "/v2/identity/auth/api/individual/".$accountId."/bankCard4Factors";
    $data = [
    	"mobileNo"=>$mobileNo,
		"bankCardNo"=>$bankCardNo,
		"repetition"=>$repetition,
	    "contextId"=>$contextId,
	    "notifyUrl"=>$notifyUrl,
	    "grade"=>$grade
	];
    $res = json_encode($data);
    $header = getHeader($data,"POST",$head_url,$appId,$secret,$url);
    $result = sendHttp($method="POST",$urlss,$header,$res);
    return $result;
}
// $accountId = "9e053884172641a5a464d80fb9dae6c7";
// $mobileNo = "15179798856";
// $bankCardNo = "6222600260001072444";
// $repetition = false;
// $contextId = "201908221430111";
// $notifyUrl = "http://www.baidu.com";
// $grade = "STANDARD";
// $a = createPhoneBankAuthPerson($accountId,$mobileNo,$bankCardNo,$repetition,$contextId,$notifyUrl,$grade,$appId,$secret,$url);
// var_dump($a);die;  

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [createPhoneBankAuthBody 发起银行4要素核身认证]
 * @param  [type] $name       [姓名]
 * @param  [type] $certType   [个人证件类型，默认身份证]
 * @param  [type] $idNo       [个人证件号]
 * @param  [type] $mobileNo   [手机号,仅限中国大陆11位手机号]
 * @param  [type] $bankCardNo [银行卡号，仅限印有“银联”字样的银行卡]
 * @param  [type] $contextId  [对接方业务上下文id]
 * @param  [type] $notifyUrl  [认证结束后异步通知地址]
 * @param  [type] $grade      [定是否使用银行卡4要素信息比对详情版]
 * @return [type]             [description]
 */
function createPhoneBankAuthBody($name,$certType,$idNo,$mobileNo,$bankCardNo,$contextId,$notifyUrl,$grade,$appId,$secret,$url){
	$urlss = $url."/v2/identity/auth/api/individual/bankCard4Factors";
	$head_url = "/v2/identity/auth/api/individual/bankCard4Factors";
    $data = [
    	"name"=>$name,
    	"certType"=>$certType,
		"idNo"=>$idNo,
		"mobileNo"=>$mobileNo,
		"bankCardNo"=>$bankCardNo,
	    "contextId"=>$contextId,
	    "notifyUrl"=>$notifyUrl,
	    "grade"=>$grade
	];
    $res = json_encode($data);
    $header = getHeader($data,"POST",$head_url,$appId,$secret,$url);
    $result = sendHttp($method="POST",$urlss,$header,$res);
    return $result;
} 
// $name = "刘颂晶";
// $certType = "INDIVIDUAL_CH_IDCARD";
// $idNo = "360731199907050379";
// $mobileNo = "15179798856";
// $bankCardNo = "6222600260001072444";
// $contextId = "201908221430111";
// $notifyUrl = "http://www.baidu.com";
// $notifyUrl = "STANDARD";
// $a = createPhoneBankAuthBody($name,$certType,$idNo,$mobileNo,$bankCardNo,$contextId,$notifyUrl,$grade,$appId,$secret,$url);
// var_dump($a);die;  

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [phoneBankAuth 银行预留手机号验证码校验]
 * @param  [type] $flowId   [流程id]
 * @param  [type] $authcode [验证码]
 * @return [type]           [description]
 */
function phoneBankAuth($flowId,$authcode,$appId,$secret,$url){
	$urlss = $url."/v2/identity/auth/pub/individual/".$flowId."/bankCard4Factors";
	$head_url = "/v2/identity/auth/pub/individual/".$flowId."/bankCard4Factors";
	$data = [
		'authcode'=>$authcode
	];
	$res = json_encode($data);
    $header = getHeader($data,"PUT",$head_url,$appId,$secret,$url);
    $result = sendHttp($method="PUT",$urlss,$header,$res);
    return $result;
}
// $flowId = "1941810112369263681";
// $authcode = "253076";
// $a = phoneBankAuth($flowId,$authcode,$appId,$secret,$url);
// var_dump($a);die;


